package com.xcity.game.activity.newplayer;

public class NewPlayerTask {
	
	public static enum State{
		DOING,
		DONE,
		GOT,
	}
//	private int tempId;
	private State state;
//	private byte typeId;

	private NewPlayerTaskTemplate template;
	private NewPlayerTaskManager vm;
	private int[] progress;
	
//	public int getTempId() {
//		return tempId;
//	}
	public State getState() {
		return state;
	}
//	public byte getTypeId() {
//		return typeId;
//	}
	public void setState(State state) {
		this.state = state;
	}
	public NewPlayerTaskTemplate getTemplate() {
		return template;
	}
	public NewPlayerTaskManager getVm() {
		return vm;
	}
	public int[] getProgress() {
		return progress;
	}
	public void setProgress(int[] progress) {
		this.progress = progress;
	}
	
	public NewPlayerTask(NewPlayerTaskManager manager, NewPlayerTaskTemplate template){
		this.vm = manager;
//		this.tempId = template.getId();
//		this.typeId = (byte) template.getType();
		this.template = template;
		this.progress = new int[]{0, 0, 0};
		state = State.DOING;
	}
	
	public NewPlayerTask(NewPlayerTaskManager manager, NewPlayerTaskTemplate template, int poolVal){
		this.vm = manager;
//		this.tempId = template.getId();
//		this.typeId = (byte) template.getType();
		this.template = template;

		int got = (poolVal & 0x800000) >> 23;
		int[] progrss = new int[3];
		progrss[0] = poolVal & 0xFFFF;
		progrss[1] = (poolVal & 0x007F0000) >> 16;
		progrss[2] = (poolVal & 0x7F000000) >> 24;
		this.progress = progrss;
		if(got == 0){
			state = State.DOING;
			NewPlayerTracer tracer = NewPlayerTracerFactory.creat(template.getType());
			if(tracer != null){
				if(tracer.isDone(this)){
					state = State.DONE;
				}
			}
//			state = State.DONE;
//			for(int i = 0; i < progrss.length; i++){
//				if(progrss[i] < template.param[i]){
//					state = State.DOING;
//					break;
//				}
//			}
		}else{
			this.state = State.GOT;
		}
		this.progress = progrss;
	}


	/**
	 * pool构成
	 * key: nptask + 活动目标tempid
	 * value: param[2] << 24 | param[1] << 16 | param[0] | ((是否领过奖励?1:0) << 23)
	 * 	其中:	param[2] 范围(0~127)
	 * 			param[1] 范围(0~127)
	 * 			param[0] 范围(0~65535)
	 * 		是否领过奖励	1:领过 0:未领
	 */
	public int calcPoolVal(){
		int ret = (progress[2] << 24) | (progress[1] << 16) | progress[0] | ((state == State.GOT?1:0) << 23);
		return ret;
	}
}
